package mamikeji.liaowa.ui.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

import mamikeji.liaowa.R;
import mamikeji.liaowa.bean.ArticleTypeBean;

/**
 * Created by 廉冲-android开发 on 2017/5/17.
 */
public class ArticleTypeAdapter extends BaseAdapter {
    List<ArticleTypeBean.DataEntity> mList = new ArrayList<>();
    LayoutInflater inflater;
    Context context;

    public ArticleTypeAdapter() {
    }

    public ArticleTypeAdapter(List<ArticleTypeBean.DataEntity> mList, Context context) {
        this.mList = mList;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void setList(List<ArticleTypeBean.DataEntity> mList) {
        this.mList = mList;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_article_type, null);
            viewHolder = new ViewHolder();

            viewHolder.textView_article_type_titlt = (TextView) convertView.findViewById(R.id.textView_article_type_titlt);
            viewHolder.textView_article_type_num = (TextView) convertView.findViewById(R.id.textView_article_type_num);
            viewHolder.imageView_article_type_bg = (SimpleDraweeView) convertView.findViewById(R.id.imageView_article_type_bg);
//            viewHolder.imageView_dayrecommend_bg = (ImageView) convertView.findViewById(R.id.imageView_dayrecommend_bg);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        ArticleTypeBean.DataEntity dataEntity = mList.get(position);

        viewHolder.textView_article_type_titlt.setText(dataEntity.getName());
        viewHolder.textView_article_type_num.setText(dataEntity.getCount() + "");

        viewHolder.imageView_article_type_bg.setImageURI(Uri.parse(dataEntity.getImgurl()));
//        Picasso.with(context).load(dataEntity.getImgurl()).into(viewHolder.imageView_article_type_bg);
        return convertView;
    }

    public class ViewHolder {
        TextView textView_article_type_titlt;
        TextView textView_article_type_num;
        SimpleDraweeView imageView_article_type_bg;
//        ImageView imageView_dayrecommend_bg;
    }

}
